package com.jiyun.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.jiyun.dao.CategoryReportMapper;
import com.jiyun.pojo.goods.CategoryReport;
import com.jiyun.service.goods.CategoryReportService;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Service
public class CategoryReportServiceImpl implements CategoryReportService {

    @Autowired
    CategoryReportMapper categoryReportMapper;

    @Override
    public List<CategoryReport> categoryReport(LocalDate date) {
        List<CategoryReport> categoryReports = categoryReportMapper.categoryReport(date);
        return categoryReports;
    }

    @Override
    public void createData() {
        LocalDate date = LocalDate.now().minusDays(1);

        List<CategoryReport> categoryReports = categoryReportMapper.categoryReport(date);
        // 将查询出来的统计数据，直接放入到数据库
        for (CategoryReport categoryReport : categoryReports) {
            categoryReportMapper.insert(categoryReport);
        }
    }

    @Override
    public List<Map> category1Count(String date1, String date2) {
        return categoryReportMapper.category1Count(date1,date2);
    }
}
